/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DatabaseConn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author anvil
 */
public class SQLBroker {
    
    public String ip, username, password;
    private Connection connection = null;
    
    public boolean connect()
    {
        try {
            Class.forName("org.postgresql.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("Where is your PostgreSQL JDBC Driver? "
                            + "Include in your library path!");
            e.printStackTrace();
            return false;
        }
        System.out.println("Driver is good!");
        
        
        try {
            
            connection = DriverManager.getConnection(
                            ip, username,
                            password);
        } catch (SQLException e) {
            System.out.println("Connection Failed! Check output console");
            e.printStackTrace();
            return false;
        }
        
        System.out.println("Connection is good!");
        return true;
    }
    
    public void setInfo(String un, String pass, String ipadd)
    {
        this.username=un;
        this.password=pass;
        this.ip=ipadd;
    }
    
    public String getUsername()
    {
        return username;
    }
    
    public String getPassword()
    {
        return password;
    }
    
    public String getIp()
    {
        return ip;
    }
    
    public void close()
    {
        try {
            connection.close();
        } catch (SQLException ex) {
            Logger.getLogger(SQLBroker.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}
